package fr.alesia.deepstack.service.impl;

import java.util.HashSet;
import java.util.Set;

import fr.alesia.deepstack.bean.Player;
import fr.alesia.deepstack.bean.Ranking;
import fr.alesia.deepstack.bean.Tournament;
import fr.alesia.deepstack.data.RankingDao;
import fr.alesia.deepstack.factory.DaoFactory;
import fr.alesia.deepstack.service.TournamentService;

public class TournamentServiceSimple implements TournamentService {

	private Tournament tournament;

	public TournamentServiceSimple(Tournament tournament){
		
		this.tournament = tournament;
	}
	
	public Set<Player> getPlayers() {
		
		RankingDao rankingDao = DaoFactory.getRankingDao();
		Set<Ranking> rankings = rankingDao.findByTournament(tournament);
		Set<Player> players = new HashSet<Player>(rankings.size());
		for (Ranking ranking : rankings) {
			players.add(ranking.getPlayer());
		}
		rankings = null;
		rankingDao = null;
		return players;
	}

	public int getNbPlayers() {
		
		RankingDao rankingDao = DaoFactory.getRankingDao();
		Set<Ranking> rankings = rankingDao.findByTournament(tournament);
		int n = rankings.size();
		rankings = null;
		rankingDao = null;
		return n;
	}

	
}
